#include "imagelabel.h"
#include "common.h"
#include "notedb.h"

#include <QContextMenuEvent>
#include <QGridLayout>
#include <QMenu>

ImageLabel::ImageLabel()
{

}

void ImageLabel::contextMenuEvent(QContextMenuEvent *event)
{
    qDebug() << "contextMenuEvent";
    deleteAction = new QAction("删除", this);
    connect(deleteAction, SIGNAL(triggered()), this, SLOT(doDeleteAction()));
    contextMenu = new QMenu();
    contextMenu->addAction(deleteAction);
    setContextMenuPolicy(Qt::DefaultContextMenu);
    contextMenu->exec(QCursor::pos());
}

ImageLabel::ImageLabel(QWidget *parent) : QLabel(parent)
{
}

void ImageLabel::doDeleteAction()
{
    qDebug() << "doDeleteAction:" << this->objectName();
    auto id = this->objectName();
    NoteDB::deleteOne(id);

    auto dlg = CommonData::dlgMap[id];
    CommonData::dlgMap.remove(id);
    emit imageChange();
    this->deleteLater();
    dlg->deleteLater();
    CommonData::imgMap.remove(id);

}

